package com.parking.carsystem.parkingchargesystem.activity;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.google.gson.Gson;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.callback.StringCallback;
import com.lzy.okgo.model.Response;
import com.parking.carsystem.parkingchargesystem.R;
import com.parking.carsystem.parkingchargesystem.common.Constant;
import com.parking.carsystem.parkingchargesystem.module.OrderMessageModel;
import com.parking.carsystem.parkingchargesystem.utils.TimeUtil;

import butterknife.BindView;
import butterknife.ButterKnife;

public class OrderMessageActivity extends BaseActivity {
    @BindView(R.id.back)
    ImageView back;
    @BindView(R.id.setting)
    TextView setting;
    @BindView(R.id.text)
    TextView text;
    @BindView(R.id.title_bg)
    RelativeLayout titleBg;
    @BindView(R.id.license_plate)
    TextView licensePlate;
    @BindView(R.id.subtotal)
    TextView subtotal;
    @BindView(R.id.subtotal_data)
    RelativeLayout subtotalData;
    @BindView(R.id.parking_information)
    TextView parkingInformation;
    @BindView(R.id.layout_information)
    LinearLayout layoutInformation;
    @BindView(R.id.park_icon)
    ImageView parkIcon;
    @BindView(R.id.parking_record)
    TextView parkingRecord;
    @BindView(R.id.time_layout)
    LinearLayout timeLayout;
    @BindView(R.id.line_one)
    View lineOne;
    @BindView(R.id.order_number)
    TextView orderNumber;
    @BindView(R.id.order_number_data)
    RelativeLayout orderNumberData;
    @BindView(R.id.charging_start_time)
    TextView chargingStartTime;
    @BindView(R.id.charging_start_data)
    RelativeLayout chargingStartData;
    @BindView(R.id.charging_end_time)
    TextView chargingEndTime;
    @BindView(R.id.order_number_data_end)
    RelativeLayout orderNumberDataEnd;
    @BindView(R.id.charging_duration)
    TextView chargingDuration;
    @BindView(R.id.charging_duration_data)
    RelativeLayout chargingDurationData;
    @BindView(R.id.charging_money)
    TextView chargingMoney;
    @BindView(R.id.charging_money_data)
    RelativeLayout chargingMoneyData;
    @BindView(R.id.line_two)
    View lineTwo;
    @BindView(R.id.show_invoice_message)
    ImageView showInvoiceMessage;
    @BindView(R.id.not_data)
    ImageView not_data;
    @BindView(R.id.invoice_status)
    TextView invoiceStatus;
    @BindView(R.id.invoice_status_msg)
    TextView invoiceStatusMsg;
    @BindView(R.id.invoice_open)
    TextView invoiceOpen;
    @BindView(R.id.invioce_status_layout)
    RelativeLayout invioceStatusLayout;
    @BindView(R.id.invoice_number)
    TextView invoiceNumber;
    @BindView(R.id.invoice_number_msg)
    TextView invoiceNumberMsg;
    @BindView(R.id.invoice_number_layout)
    RelativeLayout invoiceNumberLayout;
    @BindView(R.id.invoice_title)
    TextView invoiceTitle;
    @BindView(R.id.invoice_title_msg)
    TextView invoiceTitleMsg;
    @BindView(R.id.invoice_title_layout)
    RelativeLayout invoiceTitleLayout;
    @BindView(R.id.invoice_allmessage)
    RelativeLayout invoiceAllmessage;
    @BindView(R.id.bill_message)
    RelativeLayout billMessage;
    private String orderRecordId;

    @Override
    protected int getContentViewId() {
        return R.layout.activity_order_message;
    }

    @Override
    public void initView() {
        text.setText("订单详情");
    }

    @Override
    public void initData() {
        orderRecordId = getIntent().getStringExtra("orderRecordId");
        showLoading();
        OkGo.<String>get(Constant.url+Constant.ORDERSELECTORDERDETAIL)
                .params("orderNo",orderRecordId)
                .execute(new StringCallback() {
                    @Override
                    public void onSuccess(Response<String> response) {
                        stopLoading();
                        Gson gson = new Gson();
                        OrderMessageModel orderMessageModel = gson.fromJson(response.body(), OrderMessageModel.class);
                        if (orderMessageModel.code == 200 && orderMessageModel.data != null) {
                            OrderMessageModel.DataBean data = orderMessageModel.data;
                            licensePlate.setText(data.plateNumber);
                            subtotal.setText(String.valueOf(data.totalFee));
                            parkingInformation.setText(data.parkinglotName);
                            parkingRecord.setText(data.payTime);
                            orderNumber.setText(data.recordId);
                            chargingStartTime.setText(data.inTime);
                            chargingEndTime.setText(TextUtils.isEmpty(data.outTime)?"暂无":data.outTime);
                            if (!TextUtils.isEmpty(data.outTime) && !TextUtils.isEmpty(data.inTime)) {
                                chargingDuration.setText(TimeUtil.getDistanceTime(data.outTime, data.inTime));
                            }else {
                                chargingDuration.setText("暂无");
                            }
                            chargingMoney.setText(String.valueOf(data.couponFee));
                        }else {
                            billMessage.setVisibility(View.GONE);
                            not_data.setVisibility(View.VISIBLE);
                        }
                    }

                    @Override
                    public void onError(Response<String> response) {
                        stopLoading();
                        billMessage.setVisibility(View.GONE);
                        not_data.setVisibility(View.VISIBLE);
                    }
                });
    }
}
